<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

</body>
<script>
  ajax('put', 'http://127.0.0.1:5501/list', JSON.stringify({ user: 'gsh' }))
  // ajax('post', 'http://127.0.0.1:5501/login', "nam='grh'&pwd='123'")
  ajax('get', 'http://127.0.0.1:5501/')
  function ajax(method, url, data) {
    return new Promise((resolve, reject) => {
      var xhr = new XMLHttpRequest()
      xhr.open(method, url)
      xhr.setRequestHeader('Content-Type', 'application/json')
      // xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
      xhr.onreadystatechange = function () {
        if (xhr.status === 200) {
          if (xhr.readyState === 4) {
            resolve(xhr.responseText)
          }
        }
      }
      xhr.send(data)
    })
  }
</script>

</html>